import {
  createStore,
  // applyMiddleware,
  // compose,
  combineReducers,
} from 'redux'
// import thunk from 'redux-thunk'
import counterReducer from './counter'
import homeReducer from './home'
import userReducer from './user'
import { log, thunk, applyMiddleWare } from './middleware'

// redux-devtools
// const composeEnhancers =
//   window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ trace: true }) || compose

// 将两个reducer合并子啊一起
const reducer = combineReducers({
  counter: counterReducer,
  home: homeReducer,
  user: userReducer,
})

// combineReduce实现原来
/* function reducer(state = {}, action) {
  // 返回一个对象，store中的state
  return {
    counter: counterReducer(state.counter, action),
    home: homeReducer(state.home, action),
    user: userReducer(state.user, action),
  }
} */

// const store = createStore(reducer, composeEnhancers(applyMiddleware(thunk)))
const store = createStore(reducer)
applyMiddleWare(store, log, thunk)

export default store
